*******************************************************************************
* .do-file to perform robustness checks on inheritances in the data
*********************************************************************************

		clear all
		set maxvar 6000
		cd "$scfwkddata"
		
		use dataset_analysis, clear
		
		
*************************************************************
************* prepare for multiple impuation ****************
*************************************************************		

		tostring Y1, replace
		g imp = substr(Y1,-1,.)
		
		tostring wave, replace
		g Y1_uni = wave+Y1
		
		destring Y1 imp wave Y1_uni, replace
		
*************************************************************
********** (expected) inheritances by family type ***********
*************************************************************

		// set as survey data
		svyset Y1 [pweight = wgt_rv] 
		
		// ever received inheritance, transfer or gift
		gen inher = 1 if inher_d == 1
		replace inher = 0 if inher_d == 5 
		
		// do you expect to receive substantial inhertiances (or assets): recode "no" from 5 to 0
		replace inher_exp = 0 if inher_exp == 5
		
		// fraction of households that ever received inheritance 
		svy: mean inher, over(fam_type)
		svy: mean inher if ageav > 55, over(fam_type)
		
		// amount of inheritance or gift (note: expressed in 2007 dollars!)
		gen inher_amt = inher1_val + inher2_val + inher3_val + inheroth_val
		
		// avearge amount by family type
		svy: mean inher_amt, over(fam_type)
		svy: mean inher_amt if ageav > 55, over(fam_type)
		
		// fraction of households who expect to receive inheritance (or transfer)
		svy: mean inher_exp, over(fam_type)
		svy: mean inher_exp if ageav > 55, over(fam_type)
		
		// fraction of households who perceive leaving inheritance as very important or important
		gen bequest_mot = 1 if inher_imp == 1 | inher_imp == 2
		* somewhat important, not important
		replace bequest_mot = 0 if inher_imp == 4 | inher_imp == 5
		
		svy: mean bequest_mot, over(fam_type)
		
		// fraction of households who expect to give a "sizable estate" themselves
		replace inher_expown = . if inher_expown == 2 // not valid category acc to codebook 
		
		replace inher_expown = 0 if inher_expown == 5
		replace inher_expown = 1 if inher_expown == 3 // recode "possbily" to "yes"
		
		svy: mean inher_expown, over(fam_type)  
		
		